package com.hy.mydesktop.client.mvc.core.builder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.hy.mydesktop.client.component.meta.GridColumnConfigModel;
import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtAppEventType;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.ItemOfAssociateToWindow;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.ComponentMetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceParameter;

public class WindowApplicationBuildTemplate {

	public static GxtComponentControllerMetaModel createSimpleWindowApplication_model1(
			String controllerMetaModelId,String windowHeading,Map<String, Object> gridMap2){
		return createDynamicWindowController(controllerMetaModelId, windowHeading, gridMap2);
		
	}
	
	public static GxtComponentControllerMetaModel createDynamicWindowController(
			String controllerMetaModelId,String windowHeading,Map<String, Object> gridMap2)
	{
		
		return createDynamicWindowController(controllerMetaModelId, windowHeading, null, gridMap2);
	}
	
	
	
	private static Map<String, Object> createItemForFormPanelMap2(
			String controllerMetaModelId,String formId, Map<String, Object> formPanelMap2) {
		
		List<ItemOfAssociateToWindow> childrenItems=new LinkedList<ItemOfAssociateToWindow>();
//		GxtToSeamServiceParameter g1=new GxtToSeamServiceParameter("positionTypeService" , "submitPersistentEntities" );
		GxtToSeamServiceParameter g1=new GxtToSeamServiceParameter(formId , "submitPersistentEntities" );
		g1.setMethodArgumentsType(null);
		ItemOfAssociateToWindow itemOfAssociateToWindow = new ItemOfAssociateToWindow();
		itemOfAssociateToWindow.setGxtToSeamServiceParameter(g1);
		EventStructureMetaModel eventStructureMetaModel = new EventStructureMetaModel();
		//eventStructureMetaModel.setRootControllerId("windowController_"+controllerMetaModelId);
		//eventStructureMetaModel.setControllerId("gridSetModuleController_"+controllerMetaModelId);
		itemOfAssociateToWindow.setEventStructureMetaModel(eventStructureMetaModel);
		itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.DATASUBMIT_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));
	    
		childrenItems.add(itemOfAssociateToWindow);
		formPanelMap2.put(ComponentMetaDataConstants.CHILDREN_ITEMS,  childrenItems) ;
		formPanelMap2.put(ComponentMetaDataConstants.CHILDREN_ITEMS_TYPE,  "data") ;
		
		return formPanelMap2;
	}

	private static Map<String, Object> createGridMap2(String controllerMetaModelId, Map<String, Object> gridMap2) {
		//List<GridColumnConfigModel> columnConfigs = new LinkedList<GridColumnConfigModel>();		
		//columnConfigs.add(new GridColumnConfigModel("TITLE","名称",200));
		//columnConfigs.add(new GridColumnConfigModel("DESCRIPTION","描述",300));
		//gridMap2.put(ComponentMetaDataConstants.GRID_COLUMNCONFIG_MODELS,columnConfigs);
		
		List<ItemOfAssociateToWindow> childrenItems=new LinkedList<ItemOfAssociateToWindow>();
		//GxtToSeamServiceParameter g1=new GxtToSeamServiceParameter("positionTypeService" , "getAllPositonType" );
		//g1.setMethodArgumentsType(null);
		ItemOfAssociateToWindow itemOfAssociateToWindow = new ItemOfAssociateToWindow();
		//itemOfAssociateToWindow.setGxtToSeamServiceParameter(g1);
		EventStructureMetaModel eventStructureMetaModel = new EventStructureMetaModel();
		eventStructureMetaModel.setRootControllerId("windowController_"+controllerMetaModelId);
		eventStructureMetaModel.setControllerId("gridSetModuleController_"+controllerMetaModelId);
		itemOfAssociateToWindow.setEventStructureMetaModel(eventStructureMetaModel);
		itemOfAssociateToWindow.setItemType(ComponentMetaDataConstants.MVC_ITEM_TYPE);
		itemOfAssociateToWindow.setRegisterEventType(new GxtAppEventType("0401"));
	
		childrenItems.add(itemOfAssociateToWindow);
		gridMap2.put(ComponentMetaDataConstants.CHILDREN_ITEMS,  childrenItems) ;
		
		return gridMap2;
	}

	public static GxtComponentControllerMetaModel createSimpleWindowApplication_model1(
			String controllerMetaModelId,String windowHeading,String formId,Map<String, Object> gridMap2){
			
		return createDynamicWindowController(controllerMetaModelId, windowHeading,formId, gridMap2);

	}

	public static GxtComponentControllerMetaModel createDynamicWindowController(
			String controllerMetaModelId, String windowHeading, String formId,
			Map<String, Object> gridMap2) {
		//String controllerMetaModelId="positionTypeServices";
		//WindowApplicationBuildTemplate.createSimpleWindowApplication_model1(controllerMetaModelId);

		//窗口+表格

		Map<String, Object> windowMap2=new HashMap<String, Object>();
//		windowMap2.put(ComponentMetaDataConstants.HEADING, "555职位类型设置");
//		windowMap2.put(ComponentMetaDataConstants.TITLE, "职位类型设置");
		windowMap2.put(ComponentMetaDataConstants.HEADING, windowHeading);
		windowMap2.put(ComponentMetaDataConstants.TITLE, windowHeading);

		GxtComponentControllerMetaNodeModel node=ControllerAndComponentMetaNodeModelCreationTemplate
		.createWindowTemplate(controllerMetaModelId,1,12,windowMap2);
		
		
		
		Map<String, Object> contentPanelMap1=new HashMap<String, Object>();
		contentPanelMap1.put(MetaDataConstants.LEFT_VALUE, 2);
		contentPanelMap1.put(MetaDataConstants.RIGHT_VALUE, 11);
		contentPanelMap1.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, controllerMetaModelId);

		Map<String, Object> contentPanelMap2=new HashMap<String, Object>();
		contentPanelMap2.put(ComponentMetaDataConstants.TITLE, "contentpanel tooltip!");

		GxtComponentControllerMetaNodeModel node2=ControllerAndComponentMetaNodeModelCreationTemplate.createContentPanelTemplate(
				contentPanelMap1,contentPanelMap2);
		
		
		/*System.err.println(node2.getLeftValue());
		System.err.println(node2.getRightValue()+"dddddddddddddddddddddd"+node.getGxtComponentMetaNodeModel().getComponentTypeEnum());
		System.err.println(node2.getGxtComponentMetaNodeModel());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnumIndex());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnumName());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnum());*/
		
		Map<String , Object> menuBarMap1=new HashMap<String, Object>();
		menuBarMap1.put(MetaDataConstants.LEFT_VALUE, 3);
		menuBarMap1.put(MetaDataConstants.RIGHT_VALUE, 4);
		menuBarMap1.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, controllerMetaModelId);
		
		Map<String , Object> menuBarMap2=new HashMap<String, Object>();			
		GxtComponentControllerMetaNodeModel node3=ControllerAndComponentMetaNodeModelCreationTemplate
		.createMenuBarTemplate(menuBarMap1,menuBarMap2);

		
		Map<String , Object> toolBarMap1=new HashMap<String, Object>();
		Map<String , Object> toolBarMap2=new HashMap<String, Object>();
	
		
		GxtComponentControllerMetaNodeModel node4=ControllerAndComponentMetaNodeModelCreationTemplate.createToolBarTemplate(
				controllerMetaModelId,5,6,toolBarMap2);
		
		Map<String , Object> formPanelMap2=new HashMap<String, Object>();
		
		//为formPanel，创建Item
		formPanelMap2= createItemForFormPanelMap2(controllerMetaModelId,formId,formPanelMap2);
		if (formPanelMap2.get(MetaDataConstants.FORM_ID)!=null) {
			formPanelMap2.put(MetaDataConstants.FORM_ID, formId);
		}

		GxtComponentControllerMetaNodeModel node45=ControllerAndComponentMetaNodeModelCreationTemplate.createFormPanelTemplate(
			controllerMetaModelId,7,10,formPanelMap2);
		
		/*Map<String, Object> sumFormPanelController=new HashMap<String, Object>();
		sumFormPanelController.put(MetaDataConstants.GXT_COMPONENT__METANODEMODEL,  this.getSumFormPanelGxtComponentMetaNodeModel());		
		GxtComponentControllerMetaNodeModel node45=new GxtComponentControllerMetaNodeModel(sumFormPanelController, 7, 10);
		node45.setRegisterEventTypes(node45.addGxtAppEventType(appEventIds));*/

		
		
		//Map<String , Object> gridMap2=new HashMap<String, Object>();
		
		//此属性，可以不写（setGridColumnConfigModels方法中，已经设置过了）
		//node2.setChildrenItemsType("data");
		
		//gridMap2= createGridMap2(controllerMetaModelId,gridMap2);
		if (gridMap2.get(MetaDataConstants.FORM_ID)!=null) {
			gridMap2.put(MetaDataConstants.FORM_ID, formId);
		}
		GxtComponentControllerMetaNodeModel node6=ControllerAndComponentMetaNodeModelCreationTemplate.
			createGridTemplate(
				controllerMetaModelId,8,9,gridMap2);
		
		/*Map<String , Object> gridController=new HashMap<String, Object>();
		String[] appEventIds={"0301","0401"};
		gridController.put(MetaDataConstants.GXT_COMPONENT__METANODEMODEL, this.getGridSetModuleGxtComponentMetaNodeModel2());		
		GxtComponentControllerMetaNodeModel node6=new GxtComponentControllerMetaNodeModel(gridController,8,9);
		node6.setRegisterEventTypes(node6.addGxtAppEventType(appEventIds));*/

		List<GxtComponentControllerMetaNodeModel> list=new ArrayList<GxtComponentControllerMetaNodeModel>();
		list.add(node);
		list.add(node2);
		list.add(node3);
		list.add(node4);
		list.add(node45);
		//list.add(node5);
		list.add(node6);
		//////////////////////////
		//list.add(node62);
		////////////////////////////////
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel=new GxtComponentControllerMetaModel(list);
		gxtComponentControllerMetaModel.setId(controllerMetaModelId);
		return gxtComponentControllerMetaModel;
					
	}

	
	
	public static GxtComponentControllerMetaModel createSimpleWindowApplication_model2(
			String controllerMetaModelId, String windowHeading, String formId,
			Map<String, Object> panelInForm) {
		return createDynamicWindowController2(controllerMetaModelId, windowHeading,formId, panelInForm);

	}
	
	
	public static GxtComponentControllerMetaModel createDynamicWindowController2(
			String controllerMetaModelId, String windowHeading, String formId,
			Map<String, Object> panelInForm) {
		//String controllerMetaModelId="positionTypeServices";
		//WindowApplicationBuildTemplate.createSimpleWindowApplication_model1(controllerMetaModelId);

		//窗口+表格

		Map<String, Object> windowMap2=new HashMap<String, Object>();
		windowMap2.put(ComponentMetaDataConstants.HEADING, windowHeading);
		windowMap2.put(ComponentMetaDataConstants.TITLE, windowHeading);

		GxtComponentControllerMetaNodeModel node=ControllerAndComponentMetaNodeModelCreationTemplate
		.createWindowTemplate(controllerMetaModelId,1,12,windowMap2);
		
		
		
		Map<String, Object> contentPanelMap1=new HashMap<String, Object>();

		Map<String, Object> contentPanelMap2=new HashMap<String, Object>();
		contentPanelMap2.put(ComponentMetaDataConstants.TITLE, "contentpanel tooltip!");

		GxtComponentControllerMetaNodeModel node2=ControllerAndComponentMetaNodeModelCreationTemplate.createContentPanelTemplate(
				controllerMetaModelId,2,11,contentPanelMap2);
		
		
		/*System.err.println(node2.getLeftValue());
		System.err.println(node2.getRightValue()+"dddddddddddddddddddddd"+node.getGxtComponentMetaNodeModel().getComponentTypeEnum());
		System.err.println(node2.getGxtComponentMetaNodeModel());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnumIndex());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnumName());
		System.err.println(node2.getGxtComponentMetaNodeModel().getComponentTypeEnum());*/
		
		Map<String , Object> menuBarMap1=new HashMap<String, Object>();
		
		Map<String , Object> menuBarMap2=new HashMap<String, Object>();			
		GxtComponentControllerMetaNodeModel node3=ControllerAndComponentMetaNodeModelCreationTemplate
		.createMenuBarTemplate(controllerMetaModelId,3,4,menuBarMap2);

		
		Map<String , Object> toolBarMap1=new HashMap<String, Object>();
		Map<String , Object> toolBarMap2=new HashMap<String, Object>();
		
		GxtComponentControllerMetaNodeModel node4=ControllerAndComponentMetaNodeModelCreationTemplate.createToolBarTemplate(
				controllerMetaModelId,5,6,toolBarMap2);
		
		
		Map<String , Object> formPanelMap2=new HashMap<String, Object>();		
		//为formPanel，创建Item
		formPanelMap2= createItemForFormPanelMap2(controllerMetaModelId,formId,formPanelMap2);
		if (formPanelMap2.get(MetaDataConstants.FORM_ID)!=null) {
			formPanelMap2.put(MetaDataConstants.FORM_ID, formId);
		}

		GxtComponentControllerMetaNodeModel node45=ControllerAndComponentMetaNodeModelCreationTemplate.createFormPanelTemplate(
			controllerMetaModelId,7,10,formPanelMap2);
		
		/*Map<String, Object> sumFormPanelController=new HashMap<String, Object>();
		sumFormPanelController.put(MetaDataConstants.GXT_COMPONENT__METANODEMODEL,  this.getSumFormPanelGxtComponentMetaNodeModel());		
		GxtComponentControllerMetaNodeModel node45=new GxtComponentControllerMetaNodeModel(sumFormPanelController, 7, 10);
		node45.setRegisterEventTypes(node45.addGxtAppEventType(appEventIds));*/

		
		//gridMap2= createGridMap2(controllerMetaModelId,gridMap2);
		GxtComponentControllerMetaNodeModel node6=ControllerAndComponentMetaNodeModelCreationTemplate.
			createPanelInFormTemplate(
				controllerMetaModelId,8,9,panelInForm);
		

		List<GxtComponentControllerMetaNodeModel> list=new ArrayList<GxtComponentControllerMetaNodeModel>();
		list.add(node);
		list.add(node2);
		list.add(node3);
		list.add(node4);
		list.add(node45);
		//list.add(node5);
		list.add(node6);
		//////////////////////////
		//list.add(node62);
		////////////////////////////////
		GxtComponentControllerMetaModel gxtComponentControllerMetaModel=new GxtComponentControllerMetaModel(list);
		gxtComponentControllerMetaModel.setId(controllerMetaModelId);
		return gxtComponentControllerMetaModel;
					
	}

	

}
